#include"comm.h"
#include<unistd.h>

int main()
{
  key_t key = ftok(PATH_NAME, PROJ_ID);
  if(key < 0)
  {
    perror("ftok");
    return 1;
  }
  
  int shmid = shmget(key, SIZE, IPC_CREAT | IPC_EXCL | 0666);
  if(shmid < 0)
  {
    perror("shmget");
    return 2;
  }
  printf("key:0x%x, shmid:%u\n",key, shmid);

  //sleep(2);
  char* mem = (char*)shmat(shmid, NULL, 0);
  printf("attach shm  done...\n");
  //sleep(10);

  /*通信*/
  while(1)
  {
    sleep(1);
    printf("%s\n", mem);
  }

  shmdt(mem);
  printf("detach shm done...\n");
  //sleep(5);

  shmctl(shmid, IPC_RMID, NULL);
  printf("shm delete success...");
  
  sleep(10);
  return 0;
}
